package com.ywd.platform.netty.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "netty.server")
public class NettyProperties {
    // ====================== 网络配置 ======================
    //socket地址和端口
    private String host = "0.0.0.0";
    private int port = 13001;

    // ====================== 线程配置 ======================
    //主线程和工作线程
    private int bossThreads = 1;
    private int workerThreads = 8;

    // ====================== TCP参数 ======================
    //队列、端口复用、长连接、禁用Nagle算法
    private int soBacklog = 128;
    private boolean soReuseaddr = true;
    private boolean soKeepalive = true;
    private boolean tcpNodelay = true;

    // ====================== 背压控制 ======================
    //写缓冲水位
    private int writeBufferLowWaterMark = 32768;  // 32KB
    private int writeBufferHighWaterMark = 65536; // 64KB

    // ====================== 高级配置 ======================
    private int connectTimeout = 3000;     // 毫秒
    private int maxFrameLength = 65536;    // 64KB
    private int readIdleTime = 60;         // 秒
    private int writeIdleTime = 30;        // 秒
    private int allIdleTime = 90;          // 秒

    /**
     * SSL 配置
     */
    private Ssl ssl = new Ssl();

    /**
     * SSL 配置内部类
     */
    @Data
    public static class Ssl {
        private Boolean enabled = false;
        private String keyStore = "classpath:keystore.jks";
        private String keyStorePassword = "changeit";
        private String keyPassword = "changeit";
        private String trustStore = "classpath:truststore.jks";
        private String trustStorePassword = "changeit";
        private String clientAuth = "none";
    }
}
